package com.hs.srm.admin.modules.inforecord.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.inforecord.dao.PointPriceDao;
import com.hs.srm.admin.modules.inforecord.entity.PointPriceEntity;
import com.hs.srm.admin.modules.inforecord.service.PointPriceService;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author xwx
 * @since 2020-06-04 09:15:11
 */
@Service("pointPriceService")
public class PointPriceServiceImpl extends ServiceImpl<PointPriceDao, PointPriceEntity> implements PointPriceService {

    @Autowired
    private PointPriceDao pointPriceDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //物料号
        String materialCode = (String) params.get("materialCode");
        //物料描述
        String materialDesc = (String) params.get("materialDesc");
        Page<PointPriceEntity> page = this.selectPage(
                new QueryParam<PointPriceEntity>(params).getPage(),
                new EntityWrapper<PointPriceEntity>()
                        .like(StringUtils.isNotBlank(materialDesc), "material_desc", materialDesc)
                        .eq(StringUtils.isNotBlank(materialCode), "material_code", materialCode)
                        .orderBy("create_date", false)
        );
        return new PageUtils(page);
    }

    /**
     * 根据物料号判断是否为点价物料
     *
     * @param materialCode
     * @return
     */
    @Override
    public boolean checkMaterialType(String materialCode) {
        boolean result = false;
        List<PointPriceEntity> list = this.selectList(new EntityWrapper<PointPriceEntity>()
                .like(StringUtils.isNotBlank(materialCode), "material_code", materialCode)
        );
        //查到数据，表示当前物料为点价物料
        if (list.size() > 0) {
            result = true;
        }
        return result;
    }
}